console.log "Starting server in #{process.env.NODE_ENV} mode ..."

express = require 'express'
app = express.createServer()

mongoose = require 'mongoose'
try
  mongoose.connect 'mongodb://localhost/languagelive'
catch e
  console.log e

require './config/globals'

app.configure ->
  app.use express.logger()
  app.use express.bodyParser()
  app.use express.static __dirname + '/public'
  app.set 'views', __dirname + '/app/views'
  app.set 'view engine', 'jade'
  app.set 'view options', { layout: 'layouts/site' }

  app.use require('./assets') {
    src: __dirname + '/app/assets'
    buildDir: __dirname + '/app/builtAssets'
    build: true
    minifyBuilds: false
  }
  img.root = 'images'
  css.root = 'styles'
  js.root = 'scripts'

app.configure 'development', ->
  app.use express.errorHandler { dumpExceptions: on, showStack: on }

app.configure 'production', ->
  app.use express.errorHandler()

app.get '/app', (req, res) ->
  res.render 'app', { layout: off }

models = require './app/models'

require('./app/controllers/users_controller')(app, models.User)

console.log "Done, listening on port 2999"

app.listen 2999
